'use strict';
/**
 * @name: 本地mongodb连接
 * @description: 本地测试的mongodb连接
 * @version: 0.0.1
 * @author: xiech
 * @Date: 2020-12-09 10:47:13
 * @LastEditors: xiech
 * @LastEditTime: 2020-12-09 10:47:14
 */

const MongoClient = require('mongodb').MongoClient;
const db_url = 'mongodb://localhost:27017/';

module.exports = async () => {
  return new Promise((resolve, reject) => {
    MongoClient.connect(db_url, { useNewUrlParser: true, useUnifiedTopology: true }, async (err, db) => {
      if (!err) {
        const result = {
          db:db,
          mongodb: db.db('mfmongodb')
        };
        resolve(result);
      } else {
        reject('连接 mongodb 失败,请查看!关于 mongodb 的连接地址，请个人连接自己局域网中的库,如果没有请自行搭建,或者寻找网管!', JSON.stringify(err));
      }
    });
  });
};